#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,q,l[1010],r[1010],op,p,s,e,a,b,c,d;
signed main(){
	freopen("study.in","r",stdin);
	freopen("study.out","w",stdout);
	scanf("%lld%lld",&n,&q);
	for(int i=1;i<n;i++)
		scanf("%lld%lld",&l[i],&r[i]);
	while(q--){
		scanf("%d",&op);
		if(op==1){
			scanf("%lld%lld%lld",&p,&e,&s);
			l[p]=e,r[p]=s;
		}else{
			int ans=0;
			scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
			if(a<c){
				for(int i=a;i<c;i++){
					if(b>r[i]) ans+=b-r[i]+1,b=r[i]-1;
					if(b<l[i]) b=l[i];
					b++;
				}
				ans+=max(b-d,0ll);
			}else{
				for(int i=a-1;i>=c;i--){
					if(b>r[i]) ans+=b-r[i]+1,b=r[i]-1;
					if(b<l[i]) b=l[i];
					b++;
				}
				ans+=max(b-d,0ll);
			}
			printf("%lld\n",ans);
		}
	}
	return 0;
}
